package test;

import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.util.Tool;
import org.apache.hadoop.util.ToolRunner;

import preprocess.DumpSaler;

import trouger.dmt.JoinTableRunner;
import trouger.dmt.JoinType;
import utils.Utils;

public class JoinSalerWangWang implements Tool{
	public static String getJoinSalerWangWangPath(String date) {
		return Utils.rootDir + date + "/SalerWangWang/";
	}
	@Override 
	public Configuration getConf() {
		return null;
	}
	
	@Override
	public void setConf(Configuration conf) {
		
	}
	/*
	 * 
	 * 1.search[1~25]
	 * 26.UUID
	 * 27.pv时间
	 * 28.直达后类目
	 * 29.商品idlist
	 * 30.clicklist[点击时间^A搜索的来源pid^A点击位置^A点击商品id(数字)^A是否为豆腐块商品^B....]
	 */
	@Override
	public int run(String[] args) throws Exception {
		String salerFile = DumpSaler.getSalerPath(args[0]);
		String output = getJoinSalerWangWangPath(args[0]);
		String wangwangFile = "/group/taobao/taobao/dw/fact/" + args[0] + "/ww_ctuapp_fatht0/";
		System.out.println("start job JoinSalerWangWang...");
		System.out.println("salerFile: " + salerFile);
		System.out.println("wangwangFile: " + wangwangFile);
		System.out.println("output: " + output);
		if (Utils.exitSystem(args))
			return -1;
		JoinTableRunner r = new JoinTableRunner();
		r.addSourceTable(salerFile, "UTF-8", "\t");
		r.addSourceTable(wangwangFile, "UTF-8", "\"");
		r.addKeyGroup("1.4, 2.2");	
		r.setJoinType(JoinType.InnerJoin);
		StringBuilder columns = new StringBuilder();
		for (int i = 1; i < 29; ++i)
			columns.append("1." + String.valueOf(i) + ", ");
		columns.append("1.30,");
		for (int i = 1; i < 30; ++i)
			columns.append("2." + String.valueOf(i) + ", ");
		columns.append("2.30");
		r.setResultFieldsEx(columns.toString());
		r.setResultTable(output);
		r.run("JoinSalerWangWang");
		return 0;		 	
	}
	
	/**
	 * @param args
	 */
	public static void main(String[] args) throws Exception {
		Utils.checkArgs(args);
		
		// TODO Auto-generated method stub
		int res = ToolRunner.run(new JoinSalerWangWang(), args);
		System.exit(res);
	}
}
